package dev.nextcore.contoller

import dev.nextcore.service.OllamaService
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*

@RestController
class ApiController(private val ollamaService: OllamaService) {

    @GetMapping("/hello")
    fun hello(): ResponseEntity<String> {
        return ResponseEntity.ok("Hello from Kotlin Spring Boot!")
    }

    @GetMapping("/users/{id}")
    fun getUser(@PathVariable id: Long): ResponseEntity<Map<String, Any>> {
        val user = mapOf(
            "id" to id,
            "name" to "John Doe",
            "email" to "john@example.com"
        )
        return ResponseEntity.ok(user)
    }

    @PostMapping("/users")
    fun createUser(@RequestBody userRequest: Map<String, String>): ResponseEntity<Map<String, Any>> {
        val newUser: Map<String, Any> = mapOf(
            "id" to 1,
            "name" to userRequest["name"] as Any,
            "email" to userRequest["email"] as Any
        )

        return ResponseEntity.status(HttpStatus.CREATED).body(newUser)
    }

    @PostMapping("/chat")
    fun chat(@RequestBody request: Map<String, String>): ResponseEntity<String> {
        val prompt = request["prompt"] ?: ""
        val response = ollamaService.chat(prompt)
        return ResponseEntity.ok(response)
    }
}